package hexui;

import hexui.components.GameConnectionPanel;
import hexui.components.ServerPanel;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import javax.swing.BorderFactory;
import javax.swing.JFrame;

public class GameConnectionWindow extends JFrame {
	private static final long serialVersionUID = 1L;

	GridBagLayout gridBagLayout;
	GameConnectionPanel gameConnectionPanel;
	ServerPanel serverPanel;

	public GameConnectionWindow(int port) {
		this.setTitle("Connect to a Hex Game Server");
		this.gameConnectionPanel = new GameConnectionPanel();
		this.serverPanel = new ServerPanel(port);
		this.gridBagLayout = new GridBagLayout();
		this.setDefaultCloseOperation(EXIT_ON_CLOSE);
		this.setLayout(gridBagLayout);
		this.setComponents();
		this.setResizable(false);
		this.setVisible(true);
		this.pack();
		
		this.serverPanel.listenForRequest();
	}

	public void setComponents() {
		GridBagConstraints gc = new GridBagConstraints();
		gc.anchor = GridBagConstraints.NORTHWEST;
		
		gc.insets = new Insets(40, 40, 40, 20);
		gc.gridx = 0;
		gc.gridy = 0;
		gc.fill = GridBagConstraints.VERTICAL;
		serverPanel.setBorder(BorderFactory.createTitledBorder("Server"));
		serverPanel.setPreferredSize(gameConnectionPanel.getPreferredSize());
		this.add(serverPanel, gc);

		gc.insets = new Insets(40, 20, 40, 40);
		gc.gridx = 1;
		gc.gridy = 0;
		gameConnectionPanel.setBorder(BorderFactory.createTitledBorder("Send request"));
		this.add(gameConnectionPanel, gc);

		

		
	}
}
